﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualTournaments.Business.Tournaments
{
    public class MatchResult
    {
        private Team _local;
        private Team _visitor;
        private byte _localGoals;
        private byte _visitorGoals;

        public MatchResult(Team local, Team visitor, byte localGoals, byte visitorGoals)
        {
            Local = local;
            Visitor = visitor;
            LocalGoals = localGoals;
            VisitorGoals = visitorGoals;
        }

        public virtual Team Local
        {
            get { return _local; }
            protected set { _local = value; }
        }

		public virtual Team Visitor
        {
            get { return _visitor; }
            protected set { _visitor = value; }
        }

        public byte LocalGoals
        {
            get { return _localGoals; }
            protected set { _localGoals = value; }
        }


        public byte VisitorGoals
        {
            get { return _visitorGoals; }
            protected set { _visitorGoals = value; }
        }

        public virtual Team GetWinner()
        {
            if (LocalGoals > VisitorGoals)
            {
                return Local;
            }
            else if (VisitorGoals > LocalGoals)
            {
                return Visitor;
            }
            return null;
        }

        public virtual Team GetLoser()
        {
            if (LocalGoals < VisitorGoals)
            {
                return Local;
            }
            else if (VisitorGoals < LocalGoals)
            {
                return Visitor;
            }
            return null;
        }

        public bool Tie()
        {
            return LocalGoals == VisitorGoals;
        }

        public override string ToString()
        {
            return String.Concat(Local.Name, " ", LocalGoals, " - ", Visitor.Name, " ", VisitorGoals);
        }
    }
}
